﻿
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
using lib.Model;
using lib.DAL;
using Common.Unit;

namespace lib.BLL
{
    public partial class Users_Bll
    {
        public Users_Model GetModelByAccount(string account)
        {
            return GetModel("fdUserAccount=@fdUserAccount", new SqlParameter("@fdUserAccount", account));
        }

        public CommonCmdResult UpdatePassword(Users_Model u, string oldPass, string newPass)
        {
            try
            {
                if (u == null) return new CommonCmdResult(false, "用户参数错误");
                if (!string.IsNullOrEmpty(oldPass)) if (Common.Security.Secure.MD5_32(oldPass.ToLower() + u.FdUserPasswordSeed) != u.FdUserPassword) return new CommonCmdResult(false, "旧密码输入错误");
                if (Common.Security.Secure.PasswordStrongTest(newPass) < 2) return new CommonCmdResult(false, "新密码强度过低，会造成严重的风险，请输入另一个新密码");
                Update("FdUserPassword=@FdUserPassword", "fdUserId=@fdUserId",
                         new SqlParameter("@fdUserId", u.FdUserId.Value),
                         new SqlParameter("@FdUserPassword", Common.Security.Secure.MD5_32(newPass.ToLower() + u.FdUserPasswordSeed)));
                return new CommonCmdResult(true, "修改成功");
            }
            catch
            {
                return new CommonCmdResult(false, "修改失败，请重试");
            }
        }
        public CommonCmdResult UpdatePassword(Users_Model u, string newPass)
        {
            return UpdatePassword(u, null, newPass);
        }

        /// <summary>
        /// 个人设置更新个人资料
        /// </summary>
        /// <returns></returns>
        public CommonCmdResult UpdateUserInfo(int uId,string name,string mobile,int sex)
        {
            Update("fdUserName=@fdUserName,fdUserMobile=@fdUserMobile,fdUserSex=@fdUserSex", "fdUserId=@fdUserId"
                , new SqlParameter("@fdUserId", uId)
                , new SqlParameter("@fdUserName", name)
                , new SqlParameter("@fdUserMobile", mobile)
                ,new SqlParameter("@fdUserSex",sex));
            return new CommonCmdResult(true, "修改成功");
        }
    }
}
  
